//
//  PopViewController.m
//  3DtouchDemo
//
//  Created by liuyang on 16/2/2.
//  Copyright © 2016年 liuyang. All rights reserved.
//

#import "PopViewController.h"
#define __MainScreenFrame [[UIScreen mainScreen] bounds]
//设备屏幕宽
#define __MainScreen_Width ((__MainScreenFrame.size.width)<(__MainScreenFrame.size.height)?(__MainScreenFrame.size.width):(__MainScreenFrame.size.height))
#define __MainScreen_Height ((__MainScreenFrame.size.height)>(__MainScreenFrame.size.width)?(__MainScreenFrame.size.height):(__MainScreenFrame.size.width))

@interface PopViewController (){
    UIImageView *_imageView;
    NSMutableArray * _previewActions;
}

@end

@implementation PopViewController
- (instancetype)initWithSCEvent:(UIImage *)img attachmentIndex:(NSInteger)index{
    if( img == nil){
        return nil;
    }
    self = [super init];
    if(self){
        _img = img;
        _index = index;
        self.view.backgroundColor = [UIColor whiteColor];
        self.view.layer.cornerRadius = 10;
        self.view.clipsToBounds = YES;
        self.view.frame = CGRectMake(0, 0, __MainScreen_Width, 300);
        _imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
        _imageView.tag = index;
        _imageView.clipsToBounds = YES;
        _imageView.userInteractionEnabled = NO;
        _imageView.image = _img;
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self.view addSubview:_imageView];
        self.preferredContentSize = CGSizeMake(0, _imageView.frame.size.height);
    }

        return self;
}

//重载方法 懒加载
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems{
    if(_previewActions == nil){
        _previewActions = [NSMutableArray array];
        //赞
        UIPreviewAction *itemPraise = [UIPreviewAction actionWithTitle:@"赞" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
            NSLog(@"aaaa");
//            [self SCPopEvtAttachmentViewWithClickPraiseButton];
        }];
        [_previewActions addObject:itemPraise];
        //保存
        UIPreviewAction *itemSave = [UIPreviewAction actionWithTitle:@"保存" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
            NSLog(@"bbbb");
//            [self saveImage:_event.attachments[_index]];
        }];
        [_previewActions addObject:itemSave];
        //TODO:分享
        
        UIPreviewAction *itemShare = [UIPreviewAction actionWithTitle:@"分享" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
            NSLog(@"分享");
        }];
        [_previewActions addObject:itemShare];
    }
    return _previewActions;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
